<template>
    <div :class="{fictionChapters : true, chapterNum : chapterNum != -1}" ref="fictionChapters">
        <div :class="{item : true, chapterName : chapterNum == item.chapterNum, notContent : contents != null && !contents[item.chapterNum]}" v-for="(item,index) in fictionChapters" :key="index">
            <div class="van-ellipsis" @click="toTemp(item)">{{ item.chapterName }}</div>
        </div>
    </div>
</template>

<script>
export default {
    props : {
        fictionChapters: {
            default: []
        },
        contents: {
            default: null
        },
        chapterNum: {
            default: -1
        },
    },
    mounted(){
        if(this.chapterNum != -1){
            let dom = this.$refs.fictionChapters
            let scrollHeight = dom.scrollHeight
            let num = 40 * this.chapterNum
            if (num > scrollHeight) {
                num = scrollHeight
            }
            dom.scrollTop = num
        }
    },
    methods : {
        
        toTemp(item){
            if(this.$route.path  == '/bookRead'){
                this.$emit('replace', item.chapterNum)
            }else{
                this.$router.push({
                    path : '/bookRead',
                    query : {
                        fid : item.fictionId,
                        chapterNum : item.chapterNum,
                        cid : item.fictionChapterId,
                        fName : item.fictionName
                    }
                })
            }
        }
    }
}
</script>

<style scoped>
.fictionChapters{
    padding: 5px;
}
.chapterNum{
    height: 100%;
    overflow-x: hidden;
    overflow-y: scroll;
}
.item{
    height: 40px;
    line-height: 40px;
    font-size: 14px;
}
.item > div{
    width: calc(100% - 10px);
    height: 100%;
}
.chapterName{
    color: #ff7800;
}
.notContent{
    color: #999;
}
</style>